#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
class Solution {
public:
    string addStrings(string num1, string num2) {
        int end1 = num1.size() - 1;
        int end2 = num2.size() - 1;
        string retstr;
        int carry = 0;
        while (end1 >= 0 || end2 >= 0)
        {
            int val1 = 0, val2 = 0;
            if (end1 >= 0)
            {
                val1 = num1[end1] - '0';
            }
            if (end2 >= 0)
            {
                val2 = num2[end2] - '0';
            }
            int ret = val1 + val2 + carry;
            carry = ret / 10;
            ret %= 10;
            retstr += ('0' + ret);
            --end1;
            --end2;
        }
        if (carry == 1)
        {
            retstr += '1';
        }
        reverse(retstr.begin(), retstr.end());
        return retstr;
    }
};